﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for khachhang
/// </summary>
public class khachhang
{
    DBConnection db = new DBConnection();
	public khachhang()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public void Insert_Taikhoan(string tendn,string tenkh,string mk,string diachi,string dt,string chucnang,string email)
    {
        string sql = "insert into KhachHang (TenDN,TenKH,MatKhau,DiaChiKH,SoDT,macn,Email) values (@TenDN,@TenKH,@MatKhau,@DiaChiKH,@SoDT,@macn,@Email)";
        SqlParameter p1 = new SqlParameter("@TenDN",tendn);
        SqlParameter p2 = new SqlParameter("@TenKH", tenkh);
        SqlParameter p3 = new SqlParameter("@MatKhau", mk);
        SqlParameter p4 = new SqlParameter("@DiaChiKH", diachi);
        SqlParameter p5 = new SqlParameter("@SoDT", dt);
        SqlParameter p6 = new SqlParameter("@macn", chucnang);
        SqlParameter p7 = new SqlParameter("@Email", email);
        db.thuchienlenh(sql,p1,p2,p3,p4,p5,p6,p7);
    }
    public string dangnhap(string tendn,string mk)
    {
        string sql = "select TenDN from KhachHang where TenDN=@tendn and MatKhau=@mk";
        SqlParameter p1 = new SqlParameter("@tendn",tendn);
        SqlParameter p2 = new SqlParameter("@mk",mk);
        object kq = db.LayDuLieu(sql,p1,p2);
        if (kq == null)
            throw new Exception("Đăng nhập không thành công ");
        return kq.ToString();
    }
    public void doimatkhau(string tendn, string mkc, string mkm)
    {
        string sql = "select TenDN from KhachHang where TenDN=@tendn and MatKhau=@mk";
        SqlParameter p1 = new SqlParameter("@tendn", tendn);
        SqlParameter p2 = new SqlParameter("@mk", mkc);
        object kq = db.LayDuLieu(sql, p1, p2);
        if (kq != null)
        {
            string sql1 = "update KhachHang set MatKhau=@mk where TenDN=@ten";
            SqlParameter p11 = new SqlParameter("@ten", tendn);
            SqlParameter p21 = new SqlParameter("@mk", mkm);
            db.thuchienlenh(sql1, p11, p21);
        }
        else throw new Exception("False");
    }
    public void laymatkhau(string tendn)
    {
        string sql = "select MatKhau from KhachHang where TenDN=@tendn ";
        SqlParameter p1 = new SqlParameter("@tendn",tendn);
        db.thuchienlenh(sql,p1);
        
    }
    public string Load_MatKhau(string tendn)
    {
        string sql = "select MatKhau from KhachHang where TenDN=@tendn";
        SqlParameter p1 = new SqlParameter("TenDN", tendn);
        object kq = db.LayDuLieu(sql, p1);
        return kq.ToString();
    }
    public string Load_Email(string tendn)
    {
        string sql = "select Email from KhachHang where TenDN=@tendn";
        SqlParameter p1 = new SqlParameter("TenDN", tendn);
        object kq = db.LayDuLieu(sql, p1);
        return kq.ToString();
    }
    public string layten(string tendn)
    {
        string sql = "select TenDN from KhachHang where TenDN=@tendn";
        SqlParameter p1 = new SqlParameter("@tendn", tendn);
        object kq = db.LayDuLieu(sql, p1);
        return kq.ToString();
    }
    public string Kiemtra_CN(string tendn)
    {
        string sql = "select Macn from khachhang where tendn=@tendn";
        SqlParameter p1 = new SqlParameter("@tendn", tendn);
        object kq = db.LayDuLieu(sql, p1);
        return kq.ToString();
    }
}